﻿using DotNetCore.CAP;
using Microsoft.AspNetCore.Mvc;
using MQCommon;
using MQCommon.Model;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace PaymentServices.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class PayController : ControllerBase
    {
        private readonly ICapPublisher capPublisher;
        public PayController(ICapPublisher capPublisher)
        {
            this.capPublisher = capPublisher;
        }
        // GET: api/<PayController>
        [Route("payment")]
        [NonAction]
        [CapSubscribe("order.payment")]
        public ActionResult<PayTime> payment(PayTime pt,[FromCap] CapHeader header)
        {
            var token=header["token"];
            DapperHelper dh=new DapperHelper();
            dh.BeginTransaction(() => {
                dh.Execute($"insert into payTime values({pt.Id},'{pt.Title}','{pt.ctreattime}','{token}')");
            }, capPublisher);
            return Content("ok");
        }

        
    }
}
